package cn.com.lsy.product.lepao.service.impl;

import cn.com.lsy.product.lepao.event.AddUserMessageEvent;
import cn.com.lsy.product.lepao.event.DelUserMessageEvent;
import cn.com.lsy.product.lepao.model.mt.entities.AddUserMessageDto;
import cn.com.lsy.product.lepao.service.IEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EventService implements IEventService {

    @Autowired
    ApplicationContext applicationContext;

    @Override
    public boolean addUserMessage(int msgId, List<String> phoneList) {

        AddUserMessageDto addUserMessageDto = new AddUserMessageDto();
        addUserMessageDto.setMsgId(msgId);
        addUserMessageDto.setPhoneList(phoneList);

        applicationContext.publishEvent(new AddUserMessageEvent(this, addUserMessageDto));

        return true;
    }

    @Override
    public boolean delUserMessage(int msgId) {

        AddUserMessageDto addUserMessageDto = new AddUserMessageDto();
        addUserMessageDto.setMsgId(msgId);

        applicationContext.publishEvent(new DelUserMessageEvent(this, addUserMessageDto));

        return true;
    }
}
